<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- creator-code-refactoring.qdoc -->
  <title>Refactoring | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Refactoring</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="creator-editor-locator.html" />
  <link rel="next" href="creator-beautifier.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="creator-editor-locator.html">Searching with the Locator</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-beautifier.html">Beautifying Source Code</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#finding-symbols">Finding Symbols</a></li>
<li class="level1"><a href="#finding-qml-types">Finding QML Types</a></li>
<li class="level1"><a href="#viewing-search-results">Viewing Search Results</a></li>
<li class="level1"><a href="#renaming-symbols">Renaming Symbols</a></li>
<li class="level1"><a href="#column-editing">Column Editing</a></li>
<li class="level1"><a href="#applying-refactoring-actions">Applying Refactoring Actions</a></li>
<li class="level2"><a href="#refactoring-c-code">Refactoring C++ Code</a></li>
<li class="level2"><a href="#refactoring-qml-code">Refactoring QML Code</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Refactoring</h1>
<span class="subtitle"></span>
<!-- $$$creator-editor-refactoring.html-description -->
<div class="descr"> <a name="details"></a>
<p>Refactor code to:</p>
<ul>
<li>Improve internal quality of your application</li>
<li>Improve performance and extensibility</li>
<li>Improve code readability and maintainability</li>
<li>Simplify code structure</li>
</ul>
<a name="finding-symbols"></a>
<h2 id="finding-symbols">Finding Symbols</h2>
<p>To find instances of a specific symbol in your Qt C++ project, place the cursor on the symbol in the editor and select <b>Tools</b> &gt; <b>C++</b> &gt; <b>Find References to Symbol Under Cursor</b> or press <b>Ctrl+Shift+U</b>.</p>
<p><b>Note: </b>You can also select <b>Edit</b> &gt; <b>Find/Replace</b> &gt; <b>Advanced Find</b> &gt; <b>C++ Symbols</b> to search for classes, functions, enums, and declarations either from files listed as part of the project or from all files that are used by the code, such as include files.</p><p class="centerAlign"><img src="images/qtcreator-search-cpp-symbols.png" alt="" /></p><a name="finding-qml-types"></a>
<h2 id="finding-qml-types">Finding QML Types</h2>
<p>To find instances of a specific QML type in a project, place the cursor on the type and select <b>Tools</b> &gt; <b>QML/JS</b> &gt; <b>Find References to Symbol Under Cursor</b> or press <b>Ctrl+Shift+U</b>.</p>
<a name="viewing-search-results"></a>
<h2 id="viewing-search-results">Viewing Search Results</h2>
<p>Qt Creator searches from the following locations:</p>
<ul>
<li>Files listed as a part of the project</li>
<li>Files directly used by the project files (for example, generated files)</li>
<li>Header files of used frameworks and libraries</li>
</ul>
<p>The <b>Search Results</b> pane shows the location and number of search hits in the current project.</p>
<p class="centerAlign"><img src="images/qtcreator-refactoring-find.png" alt="" /></p><p>You can browse the search results in the following ways:</p>
<ul>
<li>To go directly to an instance, double-click the instance in the <b>Search Results</b> pane.</li>
<li>To move between instances, click the <img src="images/next.png" alt="" /> (<b>Next Item</b>) button and <img src="images/prev.png" alt="" /> (<b>Previous Item</b>) button in the <b>Search Results</b> pane.</li>
<li>To expand and collapse the list of all instances, click the <img src="images/qtcreator-expand.png" alt="" /> (<b>Expand All</b>) button.</li>
<li>To clear the search results, click the <img src="images/clean_pane_small.png" alt="" /> (<b>Clear</b>) button.</li>
<li>To start a new search, click the <img src="images/qtcreator-new-search-icon.png" alt="" /> (<b>New Search</b>) button.</li>
</ul>
<a name="renaming-symbols"></a>
<h2 id="renaming-symbols">Renaming Symbols</h2>
<p>You can rename symbols in all files in a project. When you rename a class, you can also change filenames that match the class name.</p>
<p>To rename a specific symbol in a Qt project, place the cursor on it and select <b>Tools</b> &gt; <b>C++</b> &gt; <b>Rename Symbol Under Cursor</b> or press <b>Ctrl+Shift+R</b>. To rename a QML type in a project, select <b>Tools</b> &gt; <b>QML/JS</b> &gt; <b>Rename Symbol Under Cursor</b> or press <b>Ctrl+Shift+R</b>.</p>
<p>The <b>Search Results</b> pane shows the location and number of instances of the symbol in the current project.</p>
<p class="centerAlign"><img src="images/qtcreator-refactoring-replace.png" alt="" /></p><p>To replace all selected instances, enter the name of the new symbol in the <b>Replace with</b> text box, and select <b>Replace</b>. To omit an instance, deselect the check box next to the instance.</p>
<p><b>Note: </b>This action replaces all selected instances of the symbol in all files listed in the <b>Search Results</b> pane. You cannot undo this action.</p><p>If the symbol is a class, select the <b>Rename files</b> check box to also change the filenames that match the class name.</p>
<p><b>Note: </b>Renaming local symbols does not open the <b>Search Results</b> pane. The instances of the symbol are highlighted in code and you can edit the symbol. All instances of the local symbol are changed as you type.</p><a name="column-editing"></a>
<h2 id="column-editing">Column Editing</h2>
<p>To apply a change to several rows in a column simultaneously, press <b>Alt</b>, select the rows, and enter or remove text. The changes are made simultaneously at the cursor position on all the selected rows.</p>
<a name="applying-refactoring-actions"></a>
<h2 id="applying-refactoring-actions">Applying Refactoring Actions</h2>
<p>Qt Creator allows you to quickly and conveniently apply actions to refactor your code by selecting them in a context menu. The actions available depend on the position of the cursor in the code editor.</p>
<p>To apply refactoring actions to C++ code, right-click an operand, conditional statement, string, or name to open a context menu. To apply refactoring actions to QML code, right-click an item ID or name.</p>
<p>In the context menu, select <b>Refactoring</b> and then select a refactoring action.</p>
<p>You can also press <b>Alt+Enter</b> to open a context menu that contains refactoring actions available in the current cursor position.</p>
<p>If you use the <a href="creator-clang-codemodel.html">Clang code model</a> to parse the C++ files, the <a href="http://clang.llvm.org/diagnostics.html">Clang fix-it hints</a> that have been integrated into Qt Creator are also available to you. In addition to the standard ways of activating refactoring actions, you can select the actions that are applicable on a line in the context menu in the left margin of the code editor.</p>
<a name="refactoring-c-code"></a>
<h3 id="refactoring-c-code">Refactoring C++ Code</h3>
<p>You can apply the following types of refactoring actions to C++ code:</p>
<ul>
<li>Change binary operands</li>
<li>Simplify if and while conditions (for example, move declarations out of if conditions)</li>
<li>Modify strings (for example, set the encoding for a string to Latin-1, mark strings translatable, and convert symbol names to camel case)</li>
<li>Create variable declarations</li>
<li>Create function declarations and definitions</li>
</ul>
<p>The following table summarizes the refactoring actions for C++ code. The action is available when the cursor is in the position described in the Activation column.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Refactoring Action</th><th >Description</th><th >Activation</th></tr></thead>
<tr valign="top" class="odd"><td >Add Curly Braces</td><td >Adds curly braces to an if statement that does not contain a compound statement. For example, rewrites<pre class="cpp">

  <span class="keyword">if</span> (a)
      b;

</pre>
<p>as</p>
<pre class="cpp">

  <span class="keyword">if</span> (a) {
      b;
  }

</pre>
</td><td ><code>if</code></td></tr>
<tr valign="top" class="even"><td >Move Declaration out of Condition</td><td >Moves a declaration out of an if or while condition to simplify the condition. For example, rewrites<pre class="cpp">

  <span class="keyword">if</span> (Type name <span class="operator">=</span> foo()) {}

</pre>
<p>as</p>
<pre class="cpp">

  Type name <span class="operator">=</span> foo;
  <span class="keyword">if</span> (name) {}

</pre>
</td><td >Name of the introduced variable</td></tr>
<tr valign="top" class="odd"><td >Rewrite Condition Using ||</td><td >Rewrites the expression according to De Morgan's laws. For example, rewrites:<pre class="cpp">

  <span class="operator">!</span>a <span class="operator">&amp;</span><span class="operator">&amp;</span> <span class="operator">!</span>b

</pre>
<p>as</p>
<pre class="cpp">

  <span class="operator">!</span>(a <span class="operator">|</span><span class="operator">|</span> b)

</pre>
</td><td ><code>&amp;&amp;</code></td></tr>
<tr valign="top" class="even"><td >Rewrite Using <i>operator</i></td><td >Rewrites an expression negating it and using the inverse operator. For example, rewrites:<ul>
<li><pre class="cpp">

  a op b

</pre>
<p>as</p>
<pre class="cpp">

  <span class="operator">!</span>(a invop b)

</pre>
</li>
<li><pre class="cpp">

  (a op b)

</pre>
<p>as</p>
<pre class="cpp">

  <span class="operator">!</span>(a invop b)

</pre>
</li>
<li><pre class="cpp">

  <span class="operator">!</span>(a op b)

</pre>
<p>as</p>
<pre class="cpp">

  (a invob b)

</pre>
</li>
</ul>
</td><td ><code>&lt;=</code>, <code>&lt;</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>==</code> or <code>!=</code></td></tr>
<tr valign="top" class="odd"><td >Split Declaration</td><td >Splits a simple declaration into several declarations. For example, rewrites:<pre class="cpp">

  <span class="type">int</span> <span class="operator">*</span>a<span class="operator">,</span> b;

</pre>
<p>as</p>
<pre class="cpp">

  <span class="type">int</span> <span class="operator">*</span>a;
  <span class="type">int</span> b;

</pre>
</td><td >Type name or variable name</td></tr>
<tr valign="top" class="even"><td >Split if Statement</td><td >Splits an if statement into several statements. For example, rewrites:<pre class="cpp">

  <span class="keyword">if</span> (something <span class="operator">&amp;</span><span class="operator">&amp;</span> something_else) {
  }

</pre>
<p>as</p>
<pre class="cpp">

  <span class="keyword">if</span> (something) {
     <span class="keyword">if</span> (something_else) {
     }
  }

</pre>
<p>and</p>
<pre class="cpp">

  <span class="keyword">if</span> (something <span class="operator">|</span><span class="operator">|</span> something_else)
      x;

</pre>
<p>with</p>
<pre class="cpp">

  <span class="keyword">if</span> (something)
      x;
  <span class="keyword">else</span> <span class="keyword">if</span> (something_else)
      x;

</pre>
</td><td ><code>&amp;&amp;</code> or <code>||</code></td></tr>
<tr valign="top" class="odd"><td >Swap Operands</td><td >Rewrites an expression in the inverse order using the inverse operator. For example, rewrites:<pre class="cpp">

  a op b

</pre>
<p>as</p>
<pre class="cpp">

  b flipop a

</pre>
</td><td ><code>&lt;=</code>, <code>&lt;</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>==</code>, <code>!=</code>, <code>&amp;&amp;</code> or <code>||</code></td></tr>
<tr valign="top" class="even"><td >Convert to Decimal</td><td >Converts an integer literal to decimal representation</td><td >Numeric literal</td></tr>
<tr valign="top" class="odd"><td >Convert to Hexadecimal</td><td >Converts an integer literal to hexadecimal representation</td><td >Numeric literal</td></tr>
<tr valign="top" class="even"><td >Convert to Octal</td><td >Converts an integer literal to octal representation</td><td >Numeric literal</td></tr>
<tr valign="top" class="odd"><td >Convert to Objective-C String Literal</td><td >Converts a string literal to an Objective-C string literal if the file type is Objective-C(++). For example, rewrites the following strings<pre class="cpp">

  <span class="string">&quot;abcd&quot;</span>
  QLatin1String(<span class="string">&quot;abcd&quot;</span>)
  QLatin1Literal(<span class="string">&quot;abcd&quot;</span>)

</pre>
<p>as</p>
<pre class="cpp">

  @<span class="string">&quot;abcd&quot;</span>

</pre>
</td><td >String literal</td></tr>
<tr valign="top" class="even"><td >Enclose in QLatin1Char()</td><td >Sets the encoding for a character to Latin-1, unless the character is already enclosed in <a href="http://doc.qt.io/qt-5/qlatin1char.html">QLatin1Char</a>, <a href="http://doc.qt.io/qt-5/qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>, tr, trUtf8, QLatin1Literal, or <a href="http://doc.qt.io/qt-5/qlatin1string.html">QLatin1String</a>. For example, rewrites<pre class="cpp">

  <span class="char">'a'</span>

</pre>
<p>as</p>
<pre class="cpp">

  QLatin1Char(<span class="char">'a'</span>)

</pre>
</td><td >String literal</td></tr>
<tr valign="top" class="odd"><td >Enclose in QLatin1String()</td><td >Sets the encoding for a string to Latin-1, unless the string is already enclosed in <a href="http://doc.qt.io/qt-5/qlatin1char.html">QLatin1Char</a>, <a href="http://doc.qt.io/qt-5/qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>, tr, trUtf8, QLatin1Literal, or <a href="http://doc.qt.io/qt-5/qlatin1string.html">QLatin1String</a>. For example, rewrites<pre class="cpp">

  <span class="string">&quot;abcd&quot;</span>

</pre>
<p>as</p>
<pre class="cpp">

  QLatin1String(<span class="string">&quot;abcd&quot;</span>)

</pre>
</td><td >String literal</td></tr>
<tr valign="top" class="even"><td >Mark as Translatable</td><td >Marks a string translatable. For example, rewrites <code>&quot;abcd&quot;</code> with one of the following options, depending on which of them is available:<pre class="cpp">

  tr(<span class="string">&quot;abcd&quot;</span>)
  <span class="type"><a href="http://doc.qt.io/qt-5/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>translate(<span class="string">&quot;CONTEXT&quot;</span><span class="operator">,</span> <span class="string">&quot;abcd&quot;</span>)
  QT_TRANSLATE_NOOP(<span class="string">&quot;GLOBAL&quot;</span><span class="operator">,</span> <span class="string">&quot;abcd&quot;</span>)

</pre>
</td><td >String literal</td></tr>
<tr valign="top" class="odd"><td >Add Definition in ..&#x2e;</td><td >Inserts a definition stub for a function declaration either in the header file (inside or outside the class) or in the implementation file. For free functions, inserts the definition after the declaration of the function or in the implementation file. Qualified names are minimized when possible, instead of always being fully expanded.<p>For example, rewrites</p>
<pre class="cpp">

  Class Foo {
      <span class="type">void</span> bar();
  };

</pre>
<p>as (inside class)</p>
<pre class="cpp">

  Class Foo {
      <span class="type">void</span> bar() {

      }
  };

</pre>
<p>as (outside class)</p>
<pre class="cpp">

  Class Foo {
      <span class="type">void</span> bar();
  };

  <span class="type">void</span> Foo<span class="operator">::</span>bar()
  {

  }

</pre>
<p>as (in implementation file)</p>
<pre class="cpp">

  <span class="comment">// Header file</span>
  Class Foo {
      <span class="type">void</span> bar();
  };

  <span class="comment">// Implementation file</span>
  <span class="type">void</span> Foo<span class="operator">::</span>bar()
  {

  }

</pre>
</td><td >Function name</td></tr>
<tr valign="top" class="even"><td >Add <code>Function</code> Declaration</td><td >Inserts the member function declaration that matches the member function definition into the class declaration. The function can be <code>public</code>, <code>protected</code>, <code>private</code>, <code>public slot</code>, <code>protected slot</code>, or <code>private slot</code>.</td><td >Function name</td></tr>
<tr valign="top" class="odd"><td >Switch with Next/Previous Parameter</td><td >Moves a parameter down or up one position in a parameter list.</td><td >Parameter in the declaration or definition of a function</td></tr>
<tr valign="top" class="even"><td >Extract Function</td><td >Moves the selected code to a new function and replaces the block of code with a call to the new function. Enter a name for the function in the <b>Extract Function Refactoring</b> dialog.</td><td >Block of code selected</td></tr>
<tr valign="top" class="odd"><td >Extract Constant as Function Parameter</td><td >Replaces the selected literal and all its occurrences with the function parameter <code>newParameter</code>. The parameter <code>newParameter</code> will have the original literal as the default value.</td><td >Block of code selected</td></tr>
<tr valign="top" class="even"><td >Add Local Declaration</td><td >Adds the type of an assignee, if the type of the right-hand side of the assignment is known. For example, rewrites<pre class="cpp">

  a <span class="operator">=</span> foo();

</pre>
<p>as</p>
<pre class="cpp">

  Type a <span class="operator">=</span> foo();

</pre>
<p>where Type is the return type of <code>foo()</code></p>
</td><td >Assignee</td></tr>
<tr valign="top" class="odd"><td >Convert to Camel Case</td><td >Converts a symbol name to camel case, where elements of the name are joined without delimiter characters and the initial character of each element is capitalized. For example, rewrites <code>an_example_symbol</code> as <code>anExampleSymbol</code> and <code>AN_EXAMPLE_SYMBOL</code> as <code>AnExampleSymbol</code></td><td >Identifier</td></tr>
<tr valign="top" class="even"><td >Complete Switch Statement</td><td >Adds all possible cases to a switch statement of the type <code>enum</code></td><td ><code>switch</code></td></tr>
<tr valign="top" class="odd"><td >Generate Missing <a href="http://doc.qt.io/qt-5/qobject.html#Q_PROPERTY">Q_PROPERTY</a> Members</td><td >Adds missing members to a <code>Q_PROPERTY</code>:<ul>
<li><code>read</code> function</li>
<li><code>write</code> function, if there is a WRITE</li>
<li><code>onChanged</code> signal, if there is a NOTIFY</li>
<li>data member with the name <code>m_&lt;propertyName&gt;</code></li>
</ul>
</td><td ><code>Q_PROPERTY</code></td></tr>
<tr valign="top" class="even"><td >Apply Changes</td><td >Keeps function declarations and definitions synchronized by checking for the matching declaration or definition when you edit a function signature and by applying the changes to the matching code.</td><td >Function signature. When this action is available, a light bulb icon appears: <img src="images/refactormarker.png" alt="" /></td></tr>
<tr valign="top" class="odd"><td >Add #include for undeclared or forward declared identifier</td><td >Adds an <code>#include</code> directive to the current file to make the definition of a symbol available.</td><td >Undeclared identifier</td></tr>
<tr valign="top" class="even"><td >Reformat Pointers or References</td><td >Reformats declarations with pointers or references according to the code style settings for the current project. In case no project is open, the current global code style settings are used.<p>For example, rewrites:</p>
<pre class="cpp">

  <span class="type">char</span><span class="operator">*</span>s;

</pre>
<p>as</p>
<pre class="cpp">

  <span class="type">char</span> <span class="operator">*</span>s;

</pre>
<p>When applied to selections, all suitable declarations in the selection are rewritten.</p>
</td><td >Declarations with pointers or references and selections containing such declarations</td></tr>
<tr valign="top" class="odd"><td >Create Getter and Setter Member Functions</td><td >Creates either both getter and setter member functions for member variables or only a getter or setter.</td><td >Member variable in class definition</td></tr>
<tr valign="top" class="even"><td >Move Function Definition</td><td >Moves a function definition to the implementation file, outside the class or back to its declaration. For example, rewrites:<pre class="cpp">

  <span class="keyword">class</span> Foo
  {
    <span class="type">void</span> bar()
    {
        <span class="comment">// do stuff here</span>
    }
  };

</pre>
<p>as</p>
<pre class="cpp">

  <span class="keyword">class</span> Foo
  {
    <span class="type">void</span> bar();
  };

  <span class="type">void</span> Foo<span class="operator">::</span>bar() {
      <span class="comment">// do stuff here</span>
  }

</pre>
</td><td >Function signature</td></tr>
<tr valign="top" class="odd"><td >Move All Function Definitions</td><td >Moves all function definitions to the implementation file or outside the class. For example, rewrites:<pre class="cpp">

  <span class="keyword">class</span> Foo
  {
    <span class="type">void</span> bar()
    {
        <span class="comment">// do stuff here</span>
    }
    <span class="type">void</span> baz()
    {
        <span class="comment">// do stuff here</span>
    }
  };

</pre>
<p>as</p>
<pre class="cpp">

  <span class="keyword">class</span> Foo
  {
    <span class="type">void</span> bar();
    <span class="type">void</span> baz();
  };

  <span class="type">void</span> Foo<span class="operator">::</span>bar() {
      <span class="comment">// do stuff here</span>
  }

  <span class="type">void</span> Foo<span class="operator">::</span>baz() {
      <span class="comment">// do stuff here</span>
  }

</pre>
</td><td >Class name</td></tr>
<tr valign="top" class="even"><td >Assign to Local Variable</td><td >Adds a local variable which stores the return value of a function call or a new expression. For example, rewrites:<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qstring.html">QString</a></span> s;
  s<span class="operator">.</span>toLatin1();

</pre>
<p>as</p>
<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qstring.html">QString</a></span> s;
  <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span> latin1 <span class="operator">=</span> s<span class="operator">.</span>toLatin1();

</pre>
<p>and</p>
<pre class="cpp">

  <span class="keyword">new</span> Foo;

</pre>
<p>as</p>
<pre class="cpp">

  Foo <span class="operator">*</span> localFoo <span class="operator">=</span> <span class="keyword">new</span> Foo;

</pre>
</td><td >Function call or class name</td></tr>
<tr valign="top" class="odd"><td >Insert (Pure) Virtual Functions</td><td >Select an insertion mode:<ul>
<li>Insert only declarations.</li>
<li>Insert declarations and the corresponding definitions inside the class.</li>
<li>Insert declarations and the corresponding definitions outside the class.</li>
<li>Insert declarations and the corresponding definitions in the implementation file (only if an implementation file exists).</li>
</ul>
<p class="centerAlign"><img src="images/qtcreator-refactoring-virtual-function-dialog.png" alt="" /></p></td><td >Class or base class name</td></tr>
<tr valign="top" class="even"><td >Optimize for-Loop</td><td >Rewrites post increment operators as pre increment operators and post decrement operators as pre decrement operators. It also moves other than string or numeric literals and id expressions from the condition of a for loop to its initializer. For example, rewrites:<pre class="cpp">

  <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> <span class="number">3</span> <span class="operator">*</span> <span class="number">2</span>; i<span class="operator">+</span><span class="operator">+</span>)

</pre>
<p>as</p>
<pre class="cpp">

  <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span><span class="operator">,</span> total <span class="operator">=</span> <span class="number">3</span> <span class="operator">*</span> <span class="number">2</span>; i <span class="operator">&lt;</span> total; <span class="operator">+</span><span class="operator">+</span>i)

</pre>
</td><td ><code>for</code></td></tr>
<tr valign="top" class="odd"><td >Escape String Literal as UTF-8</td><td >Escapes non-ASCII characters in a string literal to hexadecimal escape sequences. String Literals are handled as UTF-8.</td><td >String literal</td></tr>
<tr valign="top" class="even"><td >Unescape String Literal as UTF-8</td><td >Unescapes octal or hexadecimal escape sequences in a string literal. String Literals are handled as UTF-8.</td><td >String literal</td></tr>
<tr valign="top" class="odd"><td >Convert to Stack Variable</td><td >Converts the selected pointer to a stack variable. For example, rewrites:<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span> <span class="operator">*</span>foo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span>(<span class="string">&quot;foo&quot;</span>);
  foo<span class="operator">-</span><span class="operator">&gt;</span>append(<span class="string">&quot;bar&quot;</span>);

</pre>
<p>as</p>
<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span> foo(<span class="string">&quot;foo&quot;</span>);
  foo<span class="operator">.</span>append(<span class="string">&quot;bar&quot;</span>);

</pre>
<p>This operation is limited to work only within function scope. Also, the coding style for pointers and references is not respected yet.</p>
</td><td >Pointer Variable</td></tr>
<tr valign="top" class="even"><td >Convert to Pointer</td><td >Converts the selected stack variable to a pointer. For example, rewrites:<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span> foo <span class="operator">=</span> <span class="string">&quot;foo&quot;</span>;
  foo<span class="operator">.</span>append(<span class="string">&quot;bar&quot;</span>);

</pre>
<p>as</p>
<pre class="cpp">

  <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span> <span class="operator">*</span>foo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="http://doc.qt.io/qt-5/qbytearray.html">QByteArray</a></span>(<span class="string">&quot;foo&quot;</span>);
  foo<span class="operator">-</span><span class="operator">&gt;</span>append(<span class="string">&quot;bar&quot;</span>);

</pre>
<p>This operation is limited to work only within function scope. Also, the coding style for pointers and references is not respected yet.</p>
</td><td >Stack Variable</td></tr>
<tr valign="top" class="odd"><td >Convert connect() to Qt 5 Style</td><td >Converts a Qt 4 <a href="http://doc.qt.io/qt-5/qobject.html#connect">QObject::connect</a>() to Qt 5 style.</td><td ><a href="http://doc.qt.io/qt-5/qobject.html#connect">QObject::connect</a>() (Qt 4 style)</td></tr>
</table></div>
<a name="refactoring-qml-code"></a>
<h3 id="refactoring-qml-code">Refactoring QML Code</h3>
<p>You can apply the following types of refactoring actions to QML code:</p>
<ul>
<li>Rename IDs</li>
<li>Split initializers</li>
<li>Move a QML type into a separate file to reuse it in other .qml files</li>
</ul>
<p>The following table summarizes the refactoring actions for QML code. The action is available when the cursor is in the position described in the Activation column.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Refactoring Action</th><th >Description</th><th >Activation</th></tr></thead>
<tr valign="top" class="odd"><td >Move Component into Separate File</td><td >Moves a QML type into a separate file. Give the new component a name and select whether properties are set for the new component or for the original one.<p class="centerAlign"><img src="images/qtcreator-move-component-into-separate-file.png" alt="" /></p></td><td >QML type name. This action is also available in the <b>Form Editor</b> in the Design mode.</td></tr>
<tr valign="top" class="even"><td >Split Initializer</td><td >Reformats a one-line type into a multi-line type. For example, rewrites<pre class="cpp">

  Item { x: <span class="number">10</span>; y: <span class="number">20</span>; width: <span class="number">10</span> }

</pre>
<p>as</p>
<pre class="cpp">

  Item {
      x: <span class="number">10</span>;
      y: <span class="number">20</span>;
      width: <span class="number">10</span>
  }

</pre>
</td><td >QML type property</td></tr>
<tr valign="top" class="odd"><td >Wrap Component in Loader</td><td >Wraps the type in a Component type and loads it dynamically in a Loader type. This is usually done to improve startup time.</td><td >QML type name</td></tr>
<tr valign="top" class="even"><td >Add a message suppression comment</td><td >Prepends the line with an annotation comment that stops the message from being generated.</td><td >Error, warning or hint from static analysis</td></tr>
</table></div>
</div>
<!-- @@@creator-editor-refactoring.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="creator-editor-locator.html">Searching with the Locator</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-beautifier.html">Beautifying Source Code</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
